from osgeo import gdal
import os


def check_subdatasets(hdf_path):
    hdf_path = os.path.abspath(hdf_path)
    ds = gdal.Open(hdf_path)
    if ds is None:
        print(f"❌ 无法打开文件: {hdf_path}")
        return
    print(f"\n📁 {os.path.basename(hdf_path)} 包含的数据集:")
    for i, (name, desc) in enumerate(ds.GetSubDatasets()):
        print(f"  {i+1:02d}: {name}")


check_subdatasets("data/modis/MOD16A2.A2024009.h27v05.061.2024027094351.hdf")
